//
//  ViewController.m
//  YCSegmentPage
//
//  Created by tangkexiong on 16/3/14.
//  Copyright © 2016年 tangkexiong. All rights reserved.
//

#import "ViewController.h"

#import "UIImage+ImageEffects.h"

#import "TableViewController.h"
#import "CollectionViewController.h"

@interface ViewController ()<YCSegmentPageVCDataSource, YCSegmentPageVCDelegate> {
    TableViewController *_table;
    CollectionViewController *_collectionView;
    TableViewController *_table1;
    
    UIImage *_defaultImg;
    UIImage *_blurImg;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    self.dataSource = self;
    self.delegate = self;
    
    _table = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
    _collectionView = [[CollectionViewController alloc] initWithNibName:@"CollectionViewController" bundle:nil];
    
    _table1 = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _defaultImg = [UIImage imageNamed:@"listdownload.jpg"];
    _blurImg = [_defaultImg applyDarkEffect];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSegmentsInSegmentPageVC:(YCSegmentPageVC *)vc {
    return 3;
}

- (UIViewController *)contentVCInSegmentPageVC:(YCSegmentPageVC *)vc atIndex:(NSInteger)index {
    if (index == 0) {
        return _table;
    } else if (index == 1) {
        return _collectionView;
    } else {
        return _table1;
    }
}

- (NSString *)titleOfSegmentInSegmentPageVC:(YCSegmentPageVC *)vc atIndex:(NSInteger)index {
    if (index == 0) {
        return @"呵呵";
    } else if (index == 1) {
        return @"哈哈";
    } else {
        return @"哼哼";
    }
}

- (UIScrollView *)scrollViewInSegmentPageVC:(YCSegmentPageVC *)vc atIndex:(NSInteger)index {
    if (index == 0) {
        return _table.tableView;
    } else if (index == 1) {
        return nil;
    } else {
        return _table1.tableView;
    }
}

- (YCSegmentPageVCHeaderView *)headerViewInSegmentPageVC:(YCSegmentPageVC *)vc {
    YCSegmentPageVCHeaderView *view = [[YCSegmentPageVCHeaderView alloc] init];
    view.backgroundColor = [UIColor redColor];
    return view;
}

- (void)segmentPageVC:(YCSegmentPageVC *)vc didChangeTopOffset:(CGFloat)topOffset {
    if (topOffset <= 64.f) {
        [vc.headerView.imgView setImage:_blurImg];
    } else {
        [vc.headerView.imgView setImage:_defaultImg];
    }
}

@end
